home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / AutoDetail.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  6.3 KB  |  152 lines

  1. package symantec.itools.db.pro;
  2.  
  3. import java.util.Hashtable;
  4. import java.util.Properties;
  5. import java.util.Vector;
  6. import symantec.itools.db.net.Param;
  7. import symantec.itools.db.net.RemoteObject;
  8. import symantec.itools.db.net.SQLConnectionException;
  9. import symantec.itools.db.net.TextParam;
  10. import symjava.sql.SQLException;
  11.  
  12. public class AutoDetail extends Request {
  13.    public static final String ONE_TO_MANY = new String("1");
  14.    public static final String ONE_TO_ONE = new String("2");
  15.    public static final String MANY_TO_ONE = new String("3");
  16.    public static final String MANY_TO_MANY = new String("4");
  17.    private final int METHOD_execute;
  18.    private final int METHOD_join = 2;
  19.    private final int METHOD_setCardinality = 3;
  20.    private final int METHOD_setOptimisticConcurrency = 7;
  21.    private final int METHOD_setUserAndPassword = 9;
  22.    private final int METHOD_getUserAndPassword = 10;
  23.    private int _id;
  24.    private RelationView _rv;
  25.    protected RemoteObject _messgr;
  26.    private int _paramIndex;
  27.  
  28.    public AutoDetail(RelationView rv, ConnectionInfo conn) {
  29.       super(rv.getSession(), conn);
  30.       this._rv = rv;
  31.       this._id = 0;
  32.    }
  33.  
  34.    public void join(int paramIndex, int resultCol) throws SQLException {
  35.       Vector params = new Vector();
  36.       params.addElement(new Param(0, paramIndex));
  37.       params.addElement(new Param(0, resultCol));
  38.       this.GetMessgr().invokeMethod(2, params);
  39.       this.setParamIndex(paramIndex + 1);
  40.    }
  41.  
  42.    public void join(int paramIndex, String resultColName) throws SQLException {
  43.       this.join(paramIndex, this.getRelationView().findProjByName(resultColName));
  44.    }
  45.  
  46.    public void join(String resultColName) throws SQLException {
  47.       this.join(this.getParamIndex(), this.getRelationView().findProjByName(resultColName));
  48.    }
  49.  
  50.    public void setDetailProperties(Properties detailProps) {
  51.       this.transferProperties(detailProps);
  52.    }
  53.  
  54.    public Properties getDetailProperties() {
  55.       return this;
  56.    }
  57.  
  58.    public RelationView executeRequest() throws SQLException {
  59.       Vector results = this.getExecuteRequestResults();
  60.       RelationView rView = new RelationView(super._sess, this._rv.getMultiView(), this._rv, results, this._rv.getMultiView().getNextLevelID(), ((Request)this).getConnectionInfo());
  61.       this._rv.addDetailRelView(rView);
  62.       if (((Request)this).getInitialRecordPos().equals(Request.REC_POS_FIRST)) {
  63.          rView.first();
  64.       } else if (((Request)this).getInitialRecordPos().equals(Request.REC_POS_NEW)) {
  65.          rView.getNewRecord();
  66.       }
  67.  
  68.       return rView;
  69.    }
  70.  
  71.    Vector getExecuteRequestResults() throws SQLException {
  72.       int retries = 0;
  73.  
  74.       while(true) {
  75.          try {
  76.             Vector params = new Vector();
  77.             params.addElement(new TextParam(1, ((Request)this).getConnectionInfo().getDBString()));
  78.             params.addElement(new TextParam(1, ((Request)this).getSQL()));
  79.             params.addElement(new Param(1, ((Request)this).getOptConc()));
  80.             params.addElement(new Param(1, 200));
  81.             params.addElement(new TextParam(1, ((Request)this).getConnectionInfo().getUser()));
  82.             params.addElement(new TextParam(1, ((Request)this).getConnectionInfo().getPassword()));
  83.             params.addElement(new Param(1, this.getCardinality()));
  84.             params.addElement(new Param(0, ((Request)this).getConnectionInfo().getAutoDisconnect()));
  85.             Vector results = this.GetMessgr().invokeMethod(0, params);
  86.             return results;
  87.          } catch (SQLConnectionException e) {
  88.             Session var10000 = super._sess;
  89.             ConnectionInfo var10001 = ((Request)this).getConnectionInfo();
  90.             ++retries;
  91.             if (!var10000.logonFailed(var10001, retries)) {
  92.                throw e;
  93.             }
  94.          }
  95.       }
  96.    }
  97.  
  98.    protected int getCardinality() {
  99.       String value = ((Properties)this).getProperty("cardinality", ONE_TO_MANY);
  100.       Integer i = Integer.valueOf(value);
  101.       return i;
  102.    }
  103.  
  104.    private void transferProperties(Properties newProps) {
  105.       if (newProps == null) {
  106.          ((Hashtable)this).put("cardinality", ONE_TO_MANY);
  107.       } else {
  108.          ((Hashtable)this).put("cardinality", newProps.getProperty("cardinality", ONE_TO_MANY));
  109.       }
  110.    }
  111.  
  112.    public void setCardinality(String setting) {
  113.       if (setting.equals("One To One")) {
  114.          ((Hashtable)this).put("recPosition", ONE_TO_ONE);
  115.       } else if (setting.equals("One To Many")) {
  116.          ((Hashtable)this).put("recPosition", ONE_TO_MANY);
  117.       } else if (setting.equals("Many To Many")) {
  118.          ((Hashtable)this).put("recPosition", MANY_TO_MANY);
  119.       } else {
  120.          ((Hashtable)this).put("recPosition", MANY_TO_ONE);
  121.       }
  122.    }
  123.  
  124.    RelationView getRelationView() {
  125.       return this._rv;
  126.    }
  127.  
  128.    protected RemoteObject GetMessgr() throws SQLException {
  129.       if (this._messgr == null) {
  130.          this._messgr = new RemoteObject("CSCLPreparedRelView", this.getID(), this.getRelationView().getSession().getClientSession());
  131.       }
  132.  
  133.       return this._messgr;
  134.    }
  135.  
  136.    int getID() throws SQLException {
  137.       if (this._id == 0) {
  138.          this._id = this.getRelationView().getAutoDetailMessgrID(((Request)this).getConnectionInfo(), ((Request)this).getSQL(), this, this);
  139.       }
  140.  
  141.       return this._id;
  142.    }
  143.  
  144.    private int getParamIndex() {
  145.       return this._paramIndex;
  146.    }
  147.  
  148.    private void setParamIndex(int paramIndex) {
  149.       this._paramIndex = paramIndex;
  150.    }
  151. }
  152.